﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04_HexadecimalToDecimal
{
    class Program
    {
        static int FromHexadecimaToDecimalConverter(string binaryNumber)
        {
            int currentPower = 0;
            int decimalNumber = 0;

            while (binaryNumber.Length > currentPower)
            {
                char a =    binaryNumber[binaryNumber.Length - currentPower - 1];
                int currentDigitValue = 0;
                switch (a)
                {
                    case 'A':
                        currentDigitValue = 10;
                        break;
                    case 'B':
                        currentDigitValue = 11;
                        break;
                    case 'C':
                        currentDigitValue = 12;
                        break;
                    case 'D':
                        currentDigitValue = 13;
                        break;
                    case 'E':
                        currentDigitValue = 14;
                        break;
                    case 'F':
                        currentDigitValue = 15;
                        break;

                    default:
                        currentDigitValue = (int)a - 48;
                        break;
                }
                decimalNumber += currentDigitValue * (int)Math.Pow(16, currentPower);
                currentPower++;
            }
            return decimalNumber;
        }

        static void Main(string[] args)
        {
            string hexadecimalNumber = Console.ReadLine();
            Console.WriteLine(FromHexadecimaToDecimalConverter(hexadecimalNumber));

           // Console.WriteLine((int)'1');
        }
    }
}
